#include "ODN_Networking.h"

namespace ouden {

CClientInterface::CClientInterface(MultiplayerClient* pPacketHandler, String sHostAddress, unsigned short iServerPort, unsigned short iClientPort)
 : m_pPacketHandler(pPacketHandler)
{
	//ctor
	
	m_pClient = RakNetworkFactory::GetRakClientInterface();
	m_pClient->Connect(sHostAddress.c_str(), iServerPort, iClientPort, 0, 0);
	
}

CClientInterface::~CClientInterface()
{
	//dtor
	
	m_pClient->Disconnect(300);
	RakNetworkFactory::DestroyRakClientInterface(m_pClient);
	
}

/*void CClientMgr::send(char* btBitStream, long iLength)
{
	
	//Sends the bitstream to the server for forwarding to all clients
	
	//TODO: Look at priority, reliability and stream and possibly have values pulled from
	// the NetEvent or something
	m_pClient->Send(btBitStream, iLength, MEDIUM_PRIORITY, RELIABLE_ORDERED, 0);
	
}*/

CServerInterface::CServerInterface(MultiplayerServer* pPacketHandler, unsigned short iMaxPlayers, unsigned short iServerPort)
 : m_pPacketHandler(pPacketHandler)
{
	//ctor
	
	m_pServer = RakNetworkFactory::GetRakServerInterface();
	m_pServer->Start(iMaxPlayers, 0, false, iServerPort);
	
}

CServerInterface::~CServerInterface()
{
	//dtor
	
	m_pServer->Disconnect(300);
	RakNetworkFactory::DestroyRakServerInterface(m_pServer);
	
}

/*void CServerMgr::send(char* btBitStream, long iLength)
{
	
	//Sends the bitstream to all clients
	
	//TODO: Look at priority, reliability and stream and possibly have values pulled from
	// the NetEvent or something
	//Also look at who to send to and also whether to use security
	m_pServer->Send(btBitStream, iLength, MEDIUM_PRIORITY, RELIABLE_ORDERED, 0, 
					UNASSIGNED_PLAYER_ID, false, true);
	
}*/

} //namespace ouden
